home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / AIncludes / Math64.a < prev    next >
Encoding:
Text File  |  1996-05-01  |  10.2 KB  |  467 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        Math64.a
  3. ;
  4. ;    Contains:    64-bit integer math Interfaces.
  5. ;
  6. ;    Version:    Technology:    System 8
  7. ;                Release:    Universal Interfaces 3.0d3 on Copland DR1
  8. ;
  9. ;    Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  10. ;
  11. ;    Bugs?:        If you find a problem with this file, send the file and version
  12. ;                information (from above) and the problem description to:
  13. ;
  14. ;                    Internet:    apple.bugs@applelink.apple.com
  15. ;                    AppleLink:    APPLE.BUGS
  16. ;
  17. ;
  18.     IF &TYPE('__MATH64__') = 'UNDEFINED' THEN
  19. __MATH64__ SET 1
  20.  
  21.     IF &TYPE('__TYPES__') = 'UNDEFINED' THEN
  22.     include 'Types.a'
  23.     ENDIF
  24. ;
  25. ;--------------------------------------------------------------------------------
  26. ;                These routines are intended to provide C software support for
  27. ;                64 bit integer types.  Their behavior should mimic anticipated
  28. ;                64 bit hardware. This implementation should replace use of the
  29. ;                "wide" type found in PowerPC.
  30. ;
  31. ;    The following routines are available for performing math on 64-bit integers:
  32. ;    
  33. ;    S64Max
  34. ;                Returns the largest representable SInt64.
  35. ;    S64Min
  36. ;                Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  37. ;                (absolute value) of this number is not representable in an SInt64.
  38. ;                That means that S64Negate(S64Min) is not representable (in fact,
  39. ;                it returns S64Min).
  40. ;    S64Add
  41. ;                Adds two integers, producing an integer result.  If an overflow
  42. ;                occurs the result is congruent mod (2^64) as if the operands and
  43. ;                result were unsigned.  No overflow is signaled.
  44. ;    
  45. ;    S64Subtract
  46. ;                Subtracts two integers, producing an integer result.  If an overflow
  47. ;                occurs the result is congruent mod (2^64) as if the operands and
  48. ;                result were unsigned.  No overflow is signaled.
  49. ;
  50. ;    S64Negate
  51. ;                Returns the additive inverse of a signed number (i.e. it returns
  52. ;                0 - the number).  S64Negate (S64Min) is not representable (in fact,
  53. ;                it returns S64Min).
  54. ;    
  55. ;    S64Absolute
  56. ;                Returns the absolute value of the number (i.e. the number if
  57. ;                it is positive, or 0 - the number if it is negative).
  58. ;                See S64Negate above.
  59. ;                
  60. ;    S64Multiply
  61. ;                Multiplies two signed numbers, producing a signed result.  Overflow
  62. ;                is ignored and the low-order part of the product is returned.  The
  63. ;                sign of the result is not guaranteed to be correct if the magnitude
  64. ;                of the product is not representable.
  65. ;    S64Divide
  66. ;                Divides dividend by divisor, returning the quotient.  The remainder
  67. ;                is returned in *remainder if remainder (the pointer) is non-NULL.
  68. ;                The sign of the remainder is the same as the sign of the dividend
  69. ;                (i.e. it takes the absolute values of the operands, does the division,
  70. ;                then fixes the sign of the quotient and remainder).  If the divisor
  71. ;                is zero, then S64Max() will be returned (or S64Min() if the dividend
  72. ;                is negative), and the remainder will be the dividend; no error is
  73. ;                reported.
  74. ;    
  75. ;    S64Set
  76. ;                Given an SInt32, returns an SInt64 with the same value.  Use this
  77. ;                routine instead of coding 64-bit constants (at least when the
  78. ;                constant will fit in an SInt32).
  79. ;    
  80. ;    S64SetU
  81. ;                Given a UInt32, returns a SInt64 with the same value.
  82. ;    
  83. ;    S64Compare
  84. ;                Given two signed numbers, left and right, returns an
  85. ;                SInt32 that compares with zero the same way left compares with
  86. ;                right.  If you wanted to perform a comparison on 64-bit integers
  87. ;                of the form:
  88. ;                        operand_1 <operation> operand_2
  89. ;                then you could use an expression of the form:
  90. ;                        xxxS64Compare(operand_1,operand_2) <operation> 0
  91. ;                to test for the same condition.
  92. ;                
  93. ;                CAUTION: DO NOT depend on the exact value returned by this routine.
  94. ;                Only the sign (i.e. positive, zero, or negative) of the result is
  95. ;                guaranteed.
  96. ;
  97. ;    S64And, S64Or, S64Eor and S64Not
  98. ;    
  99. ;                Return Boolean (1 or 0) depending on the outcome of the logical
  100. ;                operation.
  101. ;
  102. ;    S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  103. ;    
  104. ;                Return the Bitwise result.
  105. ;                
  106. ;    S64ShiftRight and S64ShiftLeft
  107. ;    
  108. ;                The lower 7 bits of the shift argument determines the amount of 
  109. ;                shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  110. ;                is a logical shift.
  111. ;
  112. ;    SInt64ToLongDouble
  113. ;                
  114. ;                Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  115. ;                long doubles, thus, the binary -> decimal conversion routines
  116. ;                in fp.h can be used to achieve SInt64 -> long double -> decimal
  117. ;                conversions.
  118. ;                
  119. ;    LongDoubleToSInt64
  120. ;    
  121. ;                Converts a long double to a SInt64.  Any decimal string that fits
  122. ;                into a SInt64 can be converted exactly into a long double, using the
  123. ;                conversion routines found in fp.h.  Then this routine can be used
  124. ;                to complete the conversion to SInt64.
  125. ;                
  126. ;                
  127. ;    
  128. ;    The corresponding UInt64 routines are also included.
  129. ;    
  130. ;--------------------------------------------------------------------------------
  131. ;
  132.     IF FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE THEN
  133.     IF GENERATINGPOWERPC THEN
  134. ;
  135. ; extern SInt64 S64Max(void )
  136. ;
  137.     IF GENERATINGCFM THEN
  138.         IMPORT_CFM_FUNCTION S64Max
  139.     ENDIF
  140.  
  141. ;
  142. ; extern SInt64 S64Min(void )
  143. ;
  144.     IF GENERATINGCFM THEN
  145.         IMPORT_CFM_FUNCTION S64Min
  146.     ENDIF
  147.  
  148. ;
  149. ; extern SInt64 S64Add(SInt64 x, SInt64 y)
  150. ;
  151.     IF GENERATINGCFM THEN
  152.         IMPORT_CFM_FUNCTION S64Add
  153.     ENDIF
  154.  
  155. ;
  156. ; extern SInt64 S64Subtract(SInt64 left, SInt64 right)
  157. ;
  158.     IF GENERATINGCFM THEN
  159.         IMPORT_CFM_FUNCTION S64Subtract
  160.     ENDIF
  161.  
  162. ;
  163. ; extern SInt64 S64Negate(SInt64 value)
  164. ;
  165.     IF GENERATINGCFM THEN
  166.         IMPORT_CFM_FUNCTION S64Negate
  167.     ENDIF
  168.  
  169. ;
  170. ; extern SInt64 S64Absolute(SInt64 value)
  171. ;
  172.     IF GENERATINGCFM THEN
  173.         IMPORT_CFM_FUNCTION S64Absolute
  174.     ENDIF
  175.  
  176. ;
  177. ; extern SInt64 S64Multiply(SInt64 xparam, SInt64 yparam)
  178. ;
  179.     IF GENERATINGCFM THEN
  180.         IMPORT_CFM_FUNCTION S64Multiply
  181.     ENDIF
  182.  
  183. ;
  184. ; extern SInt64 S64Divide(SInt64 dividend, SInt64 divisor, SInt64 *remainder)
  185. ;
  186.     IF GENERATINGCFM THEN
  187.         IMPORT_CFM_FUNCTION S64Divide
  188.     ENDIF
  189.  
  190. ;
  191. ; extern SInt64 S64Set(SInt32 value)
  192. ;
  193.     IF GENERATINGCFM THEN
  194.         IMPORT_CFM_FUNCTION S64Set
  195.     ENDIF
  196.  
  197. ;
  198. ; extern SInt64 S64SetU(UInt32 value)
  199. ;
  200.     IF GENERATINGCFM THEN
  201.         IMPORT_CFM_FUNCTION S64SetU
  202.     ENDIF
  203.  
  204. ;
  205. ; extern SInt32 S32Set(SInt64 value)
  206. ;
  207.     IF GENERATINGCFM THEN
  208.         IMPORT_CFM_FUNCTION S32Set
  209.     ENDIF
  210.  
  211. ;
  212. ; extern long S64Compare(SInt64 left, SInt64 right)
  213. ;
  214.     IF GENERATINGCFM THEN
  215.         IMPORT_CFM_FUNCTION S64Compare
  216.     ENDIF
  217.  
  218. ;
  219. ; extern Boolean S64And(SInt64 left, SInt64 right)
  220. ;
  221.     IF GENERATINGCFM THEN
  222.         IMPORT_CFM_FUNCTION S64And
  223.     ENDIF
  224.  
  225. ;
  226. ; extern Boolean S64Or(SInt64 left, SInt64 right)
  227. ;
  228.     IF GENERATINGCFM THEN
  229.         IMPORT_CFM_FUNCTION S64Or
  230.     ENDIF
  231.  
  232. ;
  233. ; extern Boolean S64Eor(SInt64 left, SInt64 right)
  234. ;
  235.     IF GENERATINGCFM THEN
  236.         IMPORT_CFM_FUNCTION S64Eor
  237.     ENDIF
  238.  
  239. ;
  240. ; extern Boolean S64Not(SInt64 value)
  241. ;
  242.     IF GENERATINGCFM THEN
  243.         IMPORT_CFM_FUNCTION S64Not
  244.     ENDIF
  245.  
  246. ;
  247. ; extern SInt64 S64BitwiseAnd(SInt64 left, SInt64 right)
  248. ;
  249.     IF GENERATINGCFM THEN
  250.         IMPORT_CFM_FUNCTION S64BitwiseAnd
  251.     ENDIF
  252.  
  253. ;
  254. ; extern SInt64 S64BitwiseOr(SInt64 left, SInt64 right)
  255. ;
  256.     IF GENERATINGCFM THEN
  257.         IMPORT_CFM_FUNCTION S64BitwiseOr
  258.     ENDIF
  259.  
  260. ;
  261. ; extern SInt64 S64BitwiseEor(SInt64 left, SInt64 right)
  262. ;
  263.     IF GENERATINGCFM THEN
  264.         IMPORT_CFM_FUNCTION S64BitwiseEor
  265.     ENDIF
  266.  
  267. ;
  268. ; extern SInt64 S64BitwiseNot(SInt64 value)
  269. ;
  270.     IF GENERATINGCFM THEN
  271.         IMPORT_CFM_FUNCTION S64BitwiseNot
  272.     ENDIF
  273.  
  274. ;
  275. ; extern SInt64 S64ShiftRight(SInt64 value, UInt32 shift)
  276. ;
  277.     IF GENERATINGCFM THEN
  278.         IMPORT_CFM_FUNCTION S64ShiftRight
  279.     ENDIF
  280.  
  281. ;
  282. ; extern SInt64 S64ShiftLeft(SInt64 value, UInt32 shift)
  283. ;
  284.     IF GENERATINGCFM THEN
  285.         IMPORT_CFM_FUNCTION S64ShiftLeft
  286.     ENDIF
  287.  
  288. ;
  289. ; extern long double SInt64ToLongDouble(SInt64 value)
  290. ;
  291.     IF GENERATINGCFM THEN
  292.         IMPORT_CFM_FUNCTION SInt64ToLongDouble
  293.     ENDIF
  294.  
  295. ;
  296. ; extern SInt64 LongDoubleToSInt64(long double value)
  297. ;
  298.     IF GENERATINGCFM THEN
  299.         IMPORT_CFM_FUNCTION LongDoubleToSInt64
  300.     ENDIF
  301.  
  302. ;
  303. ; extern UInt64 U64Max(void )
  304. ;
  305.     IF GENERATINGCFM THEN
  306.         IMPORT_CFM_FUNCTION U64Max
  307.     ENDIF
  308.  
  309. ;
  310. ; extern UInt64 U64Add(UInt64 x, UInt64 y)
  311. ;
  312.     IF GENERATINGCFM THEN
  313.         IMPORT_CFM_FUNCTION U64Add
  314.     ENDIF
  315.  
  316. ;
  317. ; extern UInt64 U64Subtract(UInt64 left, UInt64 right)
  318. ;
  319.     IF GENERATINGCFM THEN
  320.         IMPORT_CFM_FUNCTION U64Subtract
  321.     ENDIF
  322.  
  323. ;
  324. ; extern UInt64 U64Multiply(UInt64 xparam, UInt64 yparam)
  325. ;
  326.     IF GENERATINGCFM THEN
  327.         IMPORT_CFM_FUNCTION U64Multiply
  328.     ENDIF
  329.  
  330. ;
  331. ; extern UInt64 U64Divide(UInt64 dividend, UInt64 divisor, UInt64 *remainder)
  332. ;
  333.     IF GENERATINGCFM THEN
  334.         IMPORT_CFM_FUNCTION U64Divide
  335.     ENDIF
  336.  
  337. ;
  338. ; extern UInt64 U64Set(SInt32 value)
  339. ;
  340.     IF GENERATINGCFM THEN
  341.         IMPORT_CFM_FUNCTION U64Set
  342.     ENDIF
  343.  
  344. ;
  345. ; extern UInt64 U64SetU(UInt32 value)
  346. ;
  347.     IF GENERATINGCFM THEN
  348.         IMPORT_CFM_FUNCTION U64SetU
  349.     ENDIF
  350.  
  351. ;
  352. ; extern UInt32 U32SetU(UInt64 value)
  353. ;
  354.     IF GENERATINGCFM THEN
  355.         IMPORT_CFM_FUNCTION U32SetU
  356.     ENDIF
  357.  
  358. ;
  359. ; extern long U64Compare(UInt64 left, UInt64 right)
  360. ;
  361.     IF GENERATINGCFM THEN
  362.         IMPORT_CFM_FUNCTION U64Compare
  363.     ENDIF
  364.  
  365. ;
  366. ; extern Boolean U64And(UInt64 left, UInt64 right)
  367. ;
  368.     IF GENERATINGCFM THEN
  369.         IMPORT_CFM_FUNCTION U64And
  370.     ENDIF
  371.  
  372. ;
  373. ; extern Boolean U64Or(UInt64 left, UInt64 right)
  374. ;
  375.     IF GENERATINGCFM THEN
  376.         IMPORT_CFM_FUNCTION U64Or
  377.     ENDIF
  378.  
  379. ;
  380. ; extern Boolean U64Eor(UInt64 left, UInt64 right)
  381. ;
  382.     IF GENERATINGCFM THEN
  383.         IMPORT_CFM_FUNCTION U64Eor
  384.     ENDIF
  385.  
  386. ;
  387. ; extern Boolean U64Not(UInt64 value)
  388. ;
  389.     IF GENERATINGCFM THEN
  390.         IMPORT_CFM_FUNCTION U64Not
  391.     ENDIF
  392.  
  393. ;
  394. ; extern UInt64 U64BitwiseAnd(UInt64 left, UInt64 right)
  395. ;
  396.     IF GENERATINGCFM THEN
  397.         IMPORT_CFM_FUNCTION U64BitwiseAnd
  398.     ENDIF
  399.  
  400. ;
  401. ; extern UInt64 U64BitwiseOr(UInt64 left, UInt64 right)
  402. ;
  403.     IF GENERATINGCFM THEN
  404.         IMPORT_CFM_FUNCTION U64BitwiseOr
  405.     ENDIF
  406.  
  407. ;
  408. ; extern UInt64 U64BitwiseEor(UInt64 left, UInt64 right)
  409. ;
  410.     IF GENERATINGCFM THEN
  411.         IMPORT_CFM_FUNCTION U64BitwiseEor
  412.     ENDIF
  413.  
  414. ;
  415. ; extern UInt64 U64BitwiseNot(UInt64 value)
  416. ;
  417.     IF GENERATINGCFM THEN
  418.         IMPORT_CFM_FUNCTION U64BitwiseNot
  419.     ENDIF
  420.  
  421. ;
  422. ; extern UInt64 U64ShiftRight(UInt64 value, UInt32 shift)
  423. ;
  424.     IF GENERATINGCFM THEN
  425.         IMPORT_CFM_FUNCTION U64ShiftRight
  426.     ENDIF
  427.  
  428. ;
  429. ; extern UInt64 U64ShiftLeft(UInt64 value, UInt32 shift)
  430. ;
  431.     IF GENERATINGCFM THEN
  432.         IMPORT_CFM_FUNCTION U64ShiftLeft
  433.     ENDIF
  434.  
  435. ;
  436. ; extern long double UInt64ToLongDouble(UInt64 value)
  437. ;
  438.     IF GENERATINGCFM THEN
  439.         IMPORT_CFM_FUNCTION UInt64ToLongDouble
  440.     ENDIF
  441.  
  442. ;
  443. ; extern UInt64 LongDoubleToUInt64(long double value)
  444. ;
  445.     IF GENERATINGCFM THEN
  446.         IMPORT_CFM_FUNCTION LongDoubleToUInt64
  447.     ENDIF
  448.  
  449. ;
  450. ; extern SInt64 UInt64ToSInt64(UInt64 value)
  451. ;
  452.     IF GENERATINGCFM THEN
  453.         IMPORT_CFM_FUNCTION UInt64ToSInt64
  454.     ENDIF
  455.  
  456. ;
  457. ; extern UInt64 SInt64ToUInt64(SInt64 value)
  458. ;
  459.     IF GENERATINGCFM THEN
  460.         IMPORT_CFM_FUNCTION SInt64ToUInt64
  461.     ENDIF
  462.  
  463.     ENDIF
  464.     ENDIF
  465.     ENDIF ; __MATH64__ 
  466.  
  467.